package models;
 
import java.util.*;
import javax.persistence.*;
 
import play.db.jpa.*;
 
@Entity
public class Box extends Model {
 
    public String name;
    public Date createdAt;
    
	// one user can own many boxes
    @ManyToOne
    public User owner;
	
	@OneToMany(mappedBy="box", cascade=CascadeType.ALL)
	public List<Item> items;
    
    public Box(User inOwner, String inName) {
		items = new ArrayList<Item>();
        name = inName;
		owner = inOwner;
        createdAt = new Date();
    }
	
	public Box addItem(String name) {
		Item newItem = new Item(name).save();
		items.add(newItem);
		this.save();
		return this;
	}
 
}